﻿using System;
using System.Web.Mvc;
using ServiceDeclaration.ViewModels;

namespace WebLogic.Controllers
{
    public class HomeController : Controller
    {
        private IApplicationService service;
        //
        // GET: /Home/
        public HomeController()
        {
            service = new ApplicationServiceClient();
        }
        [Authorize]
        public ActionResult Index()
        {
            return View();
        }
        [Authorize]
        public bool LaunchApplication(int applicationId, string date, string time)
        {
            var deserializedDate = DateTime.Parse(date + " " + time);
            if (deserializedDate > DateTime.Now)
            {
                service.LaunchApplication(new ApplicationViewModel() {Id = applicationId}, deserializedDate);
                return true;
            }
            else
            {
                return false;
            }

        }
        [Authorize]
        public ActionResult ViewApplicationList()
        {
            var applicationList = service.GetApplicationList();
            return View(applicationList);
        }

        [Authorize]
        public ActionResult ViewFutureTasks()
        {
            var applications = service.GetActiveTasks();
            return View(applications);
        }
    }
}
